#include"UnitHM.h"

#include"Field.h"
#include"Map.h"

#include<stdio.h>

#include<QMap>

UnitHM::UnitHM(Map *map, UnitAge age, Team team):Unit(map, team, _getFullName(age), "HM", age){
	_initStats(age);
	m_hasRetaliated = false;
}

UnitHM::~UnitHM(){
	
}

//TODO: This could probably use some tweaking.
///Regardless, this should suffice for now.
double UnitHM::getAttackPriority(const Unit *unit)const{
	double priority = 0;
	priority += (10 - unit->health());
	if(unit->type() == TYPE_LM)
		priority += 10;
	else if(unit->type() != TYPE_SR && unit->type() != TYPE_LR)
		priority += 5;
	priority += unit->attack(true)/100.0;
	priority -= unit->defense(true)/100.0;
	return priority;
}

int UnitHM::getFieldPriorityForField(Field *field)const{
	if(field->type() == FIELD_GRASS)
		return 2;
	return 0;
}

QString UnitHM::_getFullName(UnitAge age){
	switch(age){
		case AGE_BRZ:
			return "Warrior";
		case AGE_IRN:
			return "Legionnaire";
		case AGE_EMA:
			return "Armored Infantry";
		case AGE_HMA:
			return "Heavy Infantry";
		case AGE_LMA:
			return "Imperial Guard";
		case AGE_CA:
			return "Grenadier";
		case AGE_IA:
			return "Howitzer";
		default:
			return "Warrior";
	}
}

void UnitHM::_initStats(UnitAge age){
	switch(age){
		case AGE_BRZ:
			m_attack = 6;
			m_defense = 9;
			m_range = 1;
			m_speed = 11;
			m_defenseBonusGrass = 2;
			m_attackBonusLM = 2;
			m_defenseBonusLM = 2;
			break;
		case AGE_IRN:
			m_attack = 8;
			m_defense = 13;
			m_range = 1;
			m_speed = 11;
			m_defenseBonusGrass = 4;
			m_attackBonusLM = 3;
			m_defenseBonusLM = 3;
			break;
		case AGE_EMA:
			m_attack = 12;
			m_defense = 17;
			m_range = 1;
			m_speed = 11;
			m_defenseBonusGrass = 5;
			m_attackBonusLM = 5;
			m_defenseBonusLM = 5;
			break;
		case AGE_HMA:
			m_attack = 15;
			m_defense = 22;
			m_range = 1;
			m_speed = 14;
			m_defenseBonusGrass = 6;
			m_attackBonusLM = 6;
			m_defenseBonusLM = 6;
			break;
		case AGE_LMA:
			m_attack = 21;
			m_defense = 30;
			m_range = 1;
			m_speed = 14;
			m_defenseBonusGrass = 7;
			m_attackBonusLM = 7;
			m_defenseBonusLM = 7;
			break;
		case AGE_CA:
			m_attack = 28;
			m_defense = 40;
			m_range = 2;
			m_speed = 12;
			m_defenseBonusGrass = 10;
			m_attackBonusLM = 10;
			m_defenseBonusLM = 10;
			break;
		case AGE_IA:
			m_attack = 25;
			m_defense = 30;
			m_range = 6;
			m_speed = 10;
			m_defenseBonusGrass = 0;
			m_attackBonusLM = 15;
			m_defenseBonusLM = 15;
			break;
	}
}

int UnitHM::defenseTerrainBonus()const{
	if(field()->type() == FIELD_GRASS)
		return m_defenseBonusGrass;
	return 0;
}

int UnitHM::defenseBonusAgainst(UnitType type)const{
	int bonus = defenseTerrainBonus();
	if(type == TYPE_LM)
		bonus += m_defenseBonusLM;
	return bonus;
}

int UnitHM::attackBonusAgainst(UnitType type)const{
	if(type == TYPE_LM)
		return m_attackBonusLM;
	return 0;
}

/*	switch(age){
		case AGE_BRZ:
			break;
		case AGE_IRN:
			break;
		case AGE_EMA:
			break;
		case AGE_HMA:
			break;
		case AGE_LMA:
			break;
		case AGE_CA:
			break;
		case AGE_IA:
			break;
		default:
			break;
	}*/ 
